package Easy.Array;

/**
 * @author: white-zhou
 * @date: 2024-09-18 17:45
 **/
public class MoveZeroes {
    public void move(int[] nums, int i, int j) {
        int temp = nums[i];
        for (int k = i; k < j; k++) {
            nums[k] = nums[k+1];
        }
        nums[j] = temp;
    }

    // 暴力解法
    public void moveZeroes(int[] nums) {
        int n = nums.length;
        for (int i = n-1, j = n-1; i >= 0; i--) {
            if (nums[i] == 0) {
                move(nums, i, j);
                j--;
            }
        }
    }
}
